#常见自动化测试函数复习
import time
from datetime import datetime

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chromium.service import ChromiumService
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager


#安装驱动
chromins = ChromeDriverManager().install()
#创建驱动对象
driver = webdriver.Chrome(service=Service(chromins))

driver.get("https://www.baidu.com/")
url = driver.current_url
title = driver.title
print(url)
print(title)
#页面跳转
driver.find_element(By.CSS_SELECTOR,"#hotsearch-content-wrapper > li:nth-child(1) > a > span.title-content-title").click()
time.sleep(2)
# #获取当前页面的句柄
# handle = driver.current_window_handle
# #切换句柄
# driver.switch_to.window(handle)
# #打印当前页面的url
# url = driver.current_url
#获取所以页面的句柄
handler = driver.window_handles
#获取当前页面的句柄
window = driver.current_window_handle

#遍历handler进行条件判断
for i in handler:
    if i!=window:
        driver.switch_to.window(i)

#打印页面的url
url = driver.current_url
print(url)
driver.close()

driver.switch_to.window(window)
url1 = driver.current_url
print(url1)
# driver.close()

driver.maximize_window()
time.sleep(1)
driver.minimize_window()
time.sleep(1)
driver.fullscreen_window()
time.sleep(1)
driver.set_window_size(100,100)
driver.implicitly_wait(1)
# time.sleep(5)

# #创建文件夹进行截图
file = "test"+datetime.now().strftime("%Y-%m-%d-%H%M%S")+".png"

#进行截图操作
driver.save_screenshot("./image/"+file)
# # driver.save_screenshot("fffff.png")

# filename = "autotest-"+datetime.now().strftime('%Y-%m-%d-%H%M%S')+'.png'
# driver.save_screenshot('./images/'+filename)



